//
//  SQLowOrderView.m
//  pai
//
//  Created by pro on 14-11-20.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQLowOrderView.h"

@implementation SQLowOrderView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+(SQLowOrderView*)initmyview
{
    NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:@"SQLowOrderView" owner:nil options:nil];
    return [nibView objectAtIndex:0];
}

-(void)initWithObject:(lowCellObject*)object image:(NSString*)imageUrl
{
    //图片
    [self.imageView setImageWithURL:[NSURL URLWithString:imageUrl]];
    //名称
    [self.nameLabel setText:object.skuname];
    //市场价
    [self.priceLabel setText:@""];
    //我的出价
    NSMutableAttributedString* placeBid = [[NSMutableAttributedString alloc]initWithString:[[NSString alloc] initWithFormat:@"我的出价：%ld豆",(long)object.auctprice]];
    [placeBid addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,5)];
    [placeBid addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5,placeBid.length-6)];
    [placeBid addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(placeBid.length-1,1)];
    self.placeBidLabel.attributedText = placeBid;
    NSInteger imagetype = 0;
    NSString* msg = @"";
    switch (object.status) {
        case 1:
        {
            break;
        }
        case 2:
        {
            if (object.hits <= 1) {
                imagetype = 1;
                msg = @"好消息！\n当前没有其他竞拍者与您出价相同。请耐心等待。";
            }else{
                imagetype = 2;
                msg = @"抱歉！\n已经有其他竞拍者与您出价相同。竞拍失败。";
            }
            break;
        }
        case 3:
        {
            if (object.auctprice < object.strikeprice) {
                imagetype = 2;
                msg = @"抱歉！\n已经有其他竞拍者与您出价相同。竞拍失败。";
            }else if(object.auctprice > object.strikeprice){
                imagetype = 2;
                msg = @"抱歉！\n本次竞拍已经结束，您的出价不是最低的。";
            }else{
                imagetype =3;
                msg = @"恭喜！\n本次竞拍已经结束，您的出价是最低的。竞拍成功";
            }
            break;
        }
        case 4:
        {
            break;
        }
        case 5:
        {
            break;
        }
        case 9:
        {
            if (object.auctprice < object.strikeprice) {
                imagetype = 2;
                msg = @"抱歉！\n已经有其他竞拍者与您出价相同。竞拍失败。";
            }else if(object.auctprice > object.strikeprice){
                imagetype = 2;
                msg = @"抱歉！\n本次竞拍已经结束，您的出价不是最低的。";
            }else{
                imagetype =3;
                msg = @"恭喜！\n本次竞拍已经结束，您的出价是最低的。竞拍成功";
            }
            break;
        }
        default:
            break;
    }
    self.msgLabel.text = msg;
    switch (imagetype) {
        case 1:
            self.typeImage.image = [UIImage imageNamed:@"low_wait"];
            break;
        case 2:
            self.typeImage.image = [UIImage imageNamed:@"low_fail"];
            break;
        case 3:
            self.typeImage.image = [UIImage imageNamed:@"low_win"];
            break;
        default:
            break;
    }
}

-(void)updateTime:(NSString*)time
{
    [self.timeLabel setText:time];
}

@end
